<template>
  <div class="app-container">
    <!--<el-row :gutter="10" class="mb8">-->
      <!--<el-col :span="1.5">-->
        <!--<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:payConfig:add']">新增</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['system:payConfig:edit']">修改</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['system:payConfig:remove']">删除</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading" @click="handleExport" v-hasPermi="['system:payConfig:export']">导出</el-button>-->
      <!--</el-col>-->
      <!--<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    <!--</el-row>-->
    <el-table v-loading="loading" :data="payConfigList" @selection-change="handleSelectionChange">
        <!--<el-table-column type="selection" width="55" align="center" />-->
          <el-table-column label="支付类型" align="center" prop="type" >
              <template slot-scope="scope">
                <el-image
                  style="height: 100px;"
                  v-if="scope.row.type=='1'"
                  :src="require('@/assets/images/wx-pay.png')">
                </el-image>
                <el-image
                  style="height: 100px;"
                  v-if="scope.row.type=='2'"
                  :src="require('@/assets/images/ali-pay.png')">
                </el-image>
              </template>
          </el-table-column>
          <el-table-column label="appId" align="center" prop="appId" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleView(scope.row)"
                v-hasPermi="['system:payConfig:query']"
              >查看</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:payConfig:edit']"
              >修改</el-button>
              <!--<el-button-->
                <!--size="mini"-->
                <!--type="text"-->
                <!--icon="el-icon-delete"-->
                <!--@click="handleDelete(scope.row)"-->
                <!--v-hasPermi="['system:payConfig:remove']"-->
              <!--&gt;删除</el-button>-->
            </template>
        </el-table-column>
    </el-table>

      <PayConfigForm ref="formRef" @cancel="getList" />
  </div>
</template>

<script>

import { listMixin } from "@/utils/mixins/listMixin";
import { listPayConfig, delPayConfig, exportPayConfig } from "@/api/system/payConfig";
import PayConfigForm from "./form.vue"

export default {
  name: "PayConfig",
  components:{ PayConfigForm },
  mixins:[ listMixin ],
  dicts: [   'sys_common_status',   ],
  data() {
    return {
      // 支付配置表格数据
      payConfigList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        appId: null,
        mchId: null,
        mchKey: null,
        keyPath: null,
        privateKeyPath: null,
        privateCertPath: null,
        certSerialNo: null,
        apiV3Key: null,
        subAppId: null,
        status: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询支付配置列表 */
    getList() {
      this.loading = true;
      listPayConfig(this.queryParams).then(response => {
        this.payConfigList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.formRef.show({"type":"ADD"});
    },
    handleView(row){
      const id = row.id || this.ids
      const option = {
        "type":"VIEW",
        "id": id
      }
      this.$refs.formRef.show(option);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      const option = {
          "type":"UPDATE",
          "id": id
      }
      this.$refs.formRef.show(option);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除支付配置编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPayConfig(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有支付配置数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportPayConfig(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
